package com.oss.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Service;

import com.oss.service.IEhcacheService;
@Service("ehcacheService")
public class EhcacheService implements IEhcacheService{

	@Autowired
	private EhCacheCacheManager em;
	/*
	 * 通过名称从缓存中获取数据
	 */
	public Object getCacheElement(String cacheKey) throws Exception {
		 ValueWrapper e = em.getCache("serviceCache").get(cacheKey);
		if (e == null) {
			return null;
		}
		return e.get();
	}

	/*
	 * 将对象添加到缓存中
	 */
	public void addToCache(String cacheKey, Object result) throws Exception {
		em.getCache("serviceCache").put(cacheKey, result);
	}
	

}
